import {CollectionUtils} from '@/utils/CollectionUtils'

export const findFileType = (fileName) => {
  fileName = fileName || ''
  if (CollectionUtils.isEmpty(fileName)) {
    return 'UNKNOWN'
  }
  const lastIndex = fileName.lastIndexOf('.')
  if (lastIndex === -1) {
    return 'UNKNOWN'
  }
  const suffix = fileName.substring(lastIndex + 1, fileName.length).toLowerCase()
  if (CollectionUtils.isEmpty(suffix)) {
    return 'UNKNOWN'
  }

  if (['png', 'jpg', 'jpeg', 'bmp', 'gif'].includes(suffix)) {
    return 'IMAGE'
  }
  if (['xls', 'xlsx'].includes(suffix)) {
    return 'EXCEL'
  }
  if (['doc', 'docx'].includes(suffix)) {
    return 'WORD'
  }
  if (['pdf'].includes(suffix)) {
    return 'PDF'
  }
  if (['ppt', 'pptx'].includes(suffix)) {
    return 'PPT'
  }
  if (['mp4', 'm2v', 'mkv'].includes(suffix)) {
    return 'VIDEO'
  }
  if (['mp3', 'wav', 'wmv'].includes(suffix)) {
    return 'MUSIC'
  }
  if (['zip', '7z', 'rar'].includes(suffix)) {
    return 'ZIP'
  }
  if (['txt'].includes(suffix)) {
    return 'TXT'
  }
  return 'UNKNOWN'
}